package Sort;

import java.util.Arrays;

public class BubbleSort {
    public static void main(String[] args) {
        int [] a ={1, 6, 9, 2, 3, 1, 5, 4,123,545,0,45,25,48,2,8,42,8,5};
        bubbleSort(a,a.length+1);
        System.out.println(Arrays.toString(a));

        int B[] = {1, 6, 9, 2, 3, 1, 5, 4,123,545,0,45,25,48,2,8,42,8,5};
        bubbleSortMy(B);
        System.out.println(Arrays.toString(B));
    }
    public static int[] bubbleSort(int[] A, int n) {

        for (int i=0;i<A.length;i++){
            for (int j=i+1;j<A.length;j++){
                if (A[i] > A[j]){
                    int tmp = A[i];
                    A[i] = A[j];
                    A[j] = tmp;
                }
            }
        }

        return A;
    }

    public static void bubbleSortMy(int A[]){
        //从小到大排序，先把大的拿到最后
        for(int i = A.length-1;i >=0;i--){
            for(int j = i-1;j>=0;j--){
                if(A[i]<A[j]){
                    int tmp = A[i];
                    A[i] = A[j];
                    A[j] = tmp;
                }
            }


        }


    }
}
